package com.example.demo.controller;

import com.example.demo.entity.ExamPaper;
import com.example.demo.entity.ExamQuestions;
import com.example.demo.service.impl.ExamQuestionsServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/questions")
@RequiredArgsConstructor
@Component
public class ExamQuestionsController {
    private final ExamQuestionsServiceImpl examQuestionsService;
    @GetMapping("/selectall")
    public List<ExamQuestions> selectAll() {
        List<ExamQuestions> list = examQuestionsService.selectAll();
        return list;
    }
    @GetMapping("/updatequestion")
    public boolean updateQuestion(Integer id,Integer state) {
        System.out.println(id);
        System.out.println(state);
        ExamQuestions examQuestions=new ExamQuestions();
        examQuestions.setId(id);
        examQuestions.setIsusable(state);
        boolean bo=examQuestionsService.updateById(examQuestions);
        return bo;
    }

    @PostMapping("/currentPaper")
    public List<ExamQuestions> selectCurrentPaper(@RequestBody ExamPaper examPaper) {
        String[] idArr=examPaper.getQuestionid().split(",");
        List<ExamQuestions> list=new ArrayList<>();
        for(int i=0;i< idArr.length;i++){
            ExamQuestions examQuestions=examQuestionsService.selectById(idArr[i]);
            list.add(examQuestions);
        }
        return list;
    }
}
